//
//  BigAndSmallPersonViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/7/27.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "BigAndSmallPersonViewController.h"
#import "BigIntellgientCell.h"
#import "OpusListModel.h"
#import "CelebrityBiographyDetailController.h"
@interface BigAndSmallPersonViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation BigAndSmallPersonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTableViewUI];
    [self testYYModel];
    // Do any additional setup after loading the view.
}
-(void)createTableViewUI{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[BigIntellgientCell class] forCellReuseIdentifier:@"BigIntellgientCell"];
    self.tableView.estimatedRowHeight = 200;
    [self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"BigIntellgientCell";
    BigIntellgientCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    OpusListModel *model = self.dataArray[indexPath.row];
    CelebrityBiographyDetailController *detailVc = [[CelebrityBiographyDetailController alloc] init];
    detailVc.inforId = model.opusId;
    [self.navigationController pushViewController:detailVc animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return scaleTopAndBottom(300);
}
-(void)testYYModel{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSDictionary *param = @{@"type":self.fileType,@"showCount":@"10",@"currentPage":@"0"};
    NSString *url = ServerIp@"/opusApp/list";
    [manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSArray *listarry = jsonDict[@"list"];
        for (NSDictionary *dict in listarry) {
            OpusListModel *model = [OpusListModel modelWithDictionary:dict];
            [self.dataArray addObject:model];
        }
        NSLog(@"%@",self.dataArray);
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
}
-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
